define(function(require, exports, module) {
	J = jQuery;
	require('layer');
	layer.config({
	    path: '/assets/vendors/layer/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
	});
	
	$(".password-sub").on("click", function(){
		var oldPassword=$("#oldPassword").val();
		var newPassword=$("#newPassword").val();
		var confirmPassword=$("#confirmPassword").val();
	
		if(newPassword.length>=6){
			if(!/^[0-9a-zA-Z_~!@#$%^&*()_+]{6,20}$/.test(newPassword)){
				$("#newPassword").closest('div').removeClass('has-success').addClass('has-error');
				$("#newPassword").focus();
				return false; 
			}
		}else{
			$("#newPassword").closest('div').removeClass('has-success').addClass('has-error');
			$("#newPassword").focus();
			return false;
		}
		
		if(confirmPassword!=newPassword){
			$(this).closest('div').removeClass('has-success').addClass('has-error');
		}else{
			$(this).closest('div').removeClass('has-error').addClass('has-success');
		}

		$.ajax({
    		url: '/member/password.json', 
    		data: {'oldPassword': oldPassword,'newPassword': newPassword,'confirmPassword':confirmPassword},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('发送错误', {icon: 2});
    		},
    		success: function(data){	
    			if(data.code==0){
    				//弹出提示5秒后刷新页面
    				layer.msg(data.message,{icon:1},function(){
    	                parent.location.reload(); // 父页面刷新
    	                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    	                parent.layer.close(index);
    	            });
    				return false;
    			}else{
    				layer.msg(data.message, {icon: 2});
				}
          	}
    	});
	});
});